package com.unbook.utils;

import org.springframework.http.HttpStatus;

import java.util.HashMap;

public class AjaxResult extends HashMap<String,Object> {
    public static String CODE = "code";
    public static String MSG = "msg";
    public static String DATA = "data";
    public AjaxResult(){};
    public AjaxResult(int code, String msg){
        super.put(CODE,code);
        super.put(MSG,msg);
    }
    public AjaxResult(int code, String msg, Object data){
        super.put(CODE,code);
        super.put(MSG,msg);
        if(data != null){
            super.put(DATA,data);
        }
    }
    public static AjaxResult success(){
        return AjaxResult.success("操作成功");
    }
    public static AjaxResult success(String msg){
        return AjaxResult.success(msg,null);
    }
    public static AjaxResult success(String msg,Object data){
        return new AjaxResult(HttpStatus.OK.value(),msg,data);
    }
    public static AjaxResult success(Object data){
        return AjaxResult.success("操作成功",data);
    }
    public static AjaxResult error(){
        return AjaxResult.error("操作失败");
    }
    public static AjaxResult error(String msg){
        return AjaxResult.error(msg,null);
    }
    public static AjaxResult error(String msg,Object data){
        return new AjaxResult(HttpStatus.INTERNAL_SERVER_ERROR.value(),msg,data);
    }
}
